package com.itfreer.form.service.metadata;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.itfreer.form.api.BaseDao;
import com.itfreer.form.api.imp.DictionaryServiceImp;
import com.itfreer.form.dao.metadata.MetadataDirectoryDao;
import com.itfreer.form.dictionary.base.DictionaryItem;
import com.itfreer.form.entity.metadata.MetadataDirectoryEntity;

/**
 * 元数据目录
 */
@Component("metadataDirectoryServiceImp")
public class MetadataDirectoryServiceImp extends DictionaryServiceImp<MetadataDirectoryEntity>
		implements MetadataDirectoryService {

	@Autowired
	private MetadataDirectoryDao metadataNamesDao;

	@Override
	protected BaseDao<MetadataDirectoryEntity> getDao() {
		return metadataNamesDao;
	}

	@Override
	public String getDictionaryName() {
		return "f_metadata_directory";
	}

	@Override
	protected DictionaryItem convert(MetadataDirectoryEntity t) {
		DictionaryItem toEntity = new DictionaryItem();
		BeanUtils.copyProperties(t, toEntity, "directoryType");
		if (t.getDirectoryType() == null || t.getDirectoryType().trim().equals("")
				|| t.getDirectoryType().trim().equals("1")) {
			toEntity.setLeaf(false);
		} else if (t.getDirectoryType().trim().equals("2") || t.getDirectoryType().trim().equals("3")) {
			toEntity.setLeaf(true);
		} else {
			toEntity.setLeaf(false);
		}
		toEntity.setInfo(t.getDirectoryType());
		return toEntity;
	}

	@Override
	protected String getDictionaryFields() {
		return "id,pid,code,display,valid,directoryType";
	}
}